package com.aoxon.cargo.util;

import android.content.Context;
import android.util.Log;

import com.aoxon.cargo.bean.GsonBean;
import com.aoxon.cargo.state.MyReturnState;


/**
 * 检测返回GsonBean中的状态
 * @author ZZJ
 *
 */
public class CheckStateUtil {
	
	/**
	 * 检测完成有提示状态的显示
	 * @param context
	 * @param gsonBean
	 * @param text
	 * @return
	 * @throws Exception
	 */
	public static boolean check(Context context,GsonBean gsonBean,String text)throws Exception{
		if(gsonBean == null) return false;
		int STATE = gsonBean.getState();
		Log.i("STATE", "_____STATE=   " + String.valueOf(STATE));
		
		switch (STATE) {
		case MyReturnState.SUCCESS:
			return true;
		case MyReturnState.COUNT_ERROR:
			ToastUtil.show(context, "无此用户");
			return false;
		case MyReturnState.PASSWORD_ERROR:
				ToastUtil.show(context, "密码出错");
				return false;
		case MyReturnState.REPEAT:
			ToastUtil.show(context, "帐号已存在");
			return false;
		case MyReturnState.IS_NULL:
			ToastUtil.show(context, "无对应的数据");
			return false;
		default:
			ToastUtil.show(context, text+"失败");
			return false;
		}
	}
	
	
	/**
	 *检测状态完成不做提示 
	 * @param context
	 * @param gsonBean
	 * @return
	 * @throws Exception
	 */
	public static boolean check(GsonBean gsonBean) throws Exception{
		int STATE = gsonBean.getState();
		Log.i("STATE", "_____STATE=   " + String.valueOf(STATE));
		
		switch (STATE) {
		case 0:
			return false;
		case 1:
			return true;
		default:
			return false;
		}
	}
	
}
